//
//  GCD-ViewController.m
//  KnowledgeHierarchy
//
//  Created by linyi on 2020/5/21.
//  Copyright © 2020 linyi. All rights reserved.
//

#import "GCD-ViewController.h"

@interface GCD_ViewController()

@property (nonatomic, strong) dispatch_source_t timer;

@end


@implementation GCD_ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    //GCD 整个过程
    
    //1.初始化
    self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
    
    // 2.设置定时器的各种属性，
    // DISPATCH_TIME_NOW：现在开始执行，
    // 1.0*NSEC_PER_SEC : 是一个宏定义，纳秒。 最后是一个线程优先级
    dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 1.0*NSEC_PER_SEC, 0);
    
    // 3.设置回调
    dispatch_source_set_event_handler(self.timer, ^{
        // 在子线程
        NSLog(@"--%@--",[NSThread currentThread]);
    });
    
    // 4.启动 timer
    dispatch_resume(self.timer);
    
    
    // Do any additional setup after loading the view.
}
@end
